namespace DotNetNuke.NavigationControl
{
    using DotNetNuke.Modules.NavigationProvider;
    using DotNetNuke.UI.WebControls;

    
    using System;
    using System.Collections;
    using System.Web.UI;

    public class DNNTreeNavigationProvider : DotNetNuke.Modules.NavigationProvider.NavigationProvider
    {
        private bool m_blnIndicateChildren;
        private DnnTree m_objTree;
        private string m_strControlID;
        private string m_strCSSBreadCrumbRoot;
        private string m_strCSSBreadCrumbSub;
        private string m_strCSSNodeHoverRoot;
        private string m_strCSSNodeHoverSub;
        private string m_strCSSNodeRoot;
        private string m_strNodeLeftHTML;
        private string m_strNodeLeftHTMLBreadCrumb;
        private string m_strNodeLeftHTMLBreadCrumbRoot;
        private string m_strNodeLeftHTMLRoot;
        private string m_strNodeRightHTML;
        private string m_strNodeRightHTMLBreadCrumb;
        private string m_strNodeRightHTMLBreadCrumbRoot;
        private string m_strNodeRightHTMLRoot;
        private string m_strNodeSelectedRoot;
        private string m_strNodeSelectedSub;
        private string m_strPathImage;

        public override void Bind(DNNNodeCollection objNodes)
        {
            IEnumerator refObjectHelperL0=null;
            if (!this.IndicateChildren)
            {
                this.IndicateChildImageSub = "";
                this.IndicateChildImageRoot = "";
                this.IndicateChildImageExpandedSub = "";
                this.IndicateChildImageExpandedRoot = "";
            }
            if ((((this.CSSNodeSelectedRoot.Length > 0) && (this.CSSNodeSelectedRoot == this.CSSNodeSelectedSub)) ? 1 : 0) != 0)
            {
                this.Tree.DefaultNodeCssClassSelected = this.CSSNodeSelectedRoot;
            }
            try
            {
                refObjectHelperL0 = objNodes.GetEnumerator();
                while (refObjectHelperL0.MoveNext())
                {
                    TreeNode objTreeItem;
                    DNNNode objNode = (DNNNode) refObjectHelperL0.Current;
                    if (objNode.Level == 0)
                    {
                        int intIndex = this.Tree.TreeNodes.Import(objNode, true);
                        objTreeItem = this.Tree.TreeNodes[intIndex];
                        if (!objNode.Enabled)
                        {
                            objTreeItem.ClickAction = eClickAction.Expand;
                        }
                        if (this.CSSNodeRoot != "")
                        {
                            objTreeItem.CSSClass = this.CSSNodeRoot;
                        }
                        if (this.CSSNodeHoverRoot != "")
                        {
                            objTreeItem.CSSClassHover = this.CSSNodeHoverRoot;
                        }
                        if (this.NodeLeftHTMLRoot != "")
                        {
                        }
                        if ((((this.Tree.DefaultNodeCssClassSelected.Length == 0) && (this.CSSNodeSelectedRoot.Length > 0)) ? 1 : 0) != 0)
                        {
                            objTreeItem.CSSClassSelected = this.CSSNodeSelectedRoot;
                        }
                        objTreeItem.CSSIcon = " ";
                        if (objNode.BreadCrumb)
                        {
                            objTreeItem.CSSClass = this.CSSBreadCrumbRoot;
                        }
                        if (this.NodeRightHTMLRoot != "")
                        {
                        }
                    }
                    else
                    {
                        try
                        {
                            TreeNode objParent = this.Tree.TreeNodes.FindNode(objNode.ParentNode.ID);
                            if (objParent == null)
                            {
                                objParent = this.Tree.TreeNodes[this.Tree.TreeNodes.Import(objNode.ParentNode.Clone(), true)];
                            }
                            objTreeItem = objParent.TreeNodes.FindNode(objNode.ID);
                            if (objTreeItem == null)
                            {
                                objTreeItem = objParent.TreeNodes[objParent.TreeNodes.Import(objNode.Clone(), true)];
                            }
                            if (!objNode.Enabled)
                            {
                                objTreeItem.ClickAction = eClickAction.Expand;
                            }
                            if (this.CSSNodeHover != "")
                            {
                                objTreeItem.CSSClassHover = this.CSSNodeHover;
                            }
                            if (this.NodeLeftHTMLSub != "")
                            {
                            }
                            if ((((this.Tree.DefaultNodeCssClassSelected.Length == 0) && (this.CSSNodeSelectedSub.Length > 0)) ? 1 : 0) != 0)
                            {
                                objTreeItem.CSSClassSelected = this.CSSNodeSelectedSub;
                            }
                            if (objNode.BreadCrumb)
                            {
                                objTreeItem.CSSClass = this.CSSBreadCrumbSub;
                            }
                            if (this.NodeRightHTMLSub != "")
                            {
                            }
                        }
                        catch (Exception exception1)
                        {
            
                            objTreeItem = null;
            
                        }
                    }
                    if (objNode.Image.Length > 0)
                    {
                        if (((!objNode.Image.StartsWith("/") && (this.PathImage.Length > 0)) ? 1 : 0) != 0)
                        {
                            objNode.Image = this.PathImage + objNode.Image;
                        }
                        objTreeItem.Image = objNode.Image;
                    }
                    objTreeItem.ToolTip = objNode.ToolTip;
                    if (objNode.Selected)
                    {
                        this.Tree.SelectNode(objNode.ID);
                    }
                    this.Bind(objNode.DNNNodes);
                }
            }
            finally
            {
                if (refObjectHelperL0 is IDisposable)
                {
                    (refObjectHelperL0 as IDisposable).Dispose();
                }
            }
        }

        public override void ClearNodes()
        {
            this.Tree.TreeNodes.Clear();
        }

        private void DNNTree_NodeClick(object source, DNNTreeNodeClickEventArgs e)
        {
            base.RaiseEvent_NodeClick(e.Node);
        }

        private void DNNTree_PopulateOnDemand(object source, DNNTreeEventArgs e)
        {
            base.RaiseEvent_PopulateOnDemand(e.Node);
        }

        public override void Initialize()
        {
            this.m_objTree = new DnnTree();
            this.Tree.ID = this.m_strControlID;
            this.Tree.NodeClick += new DnnTree.DNNTreeNodeClickHandler(this.DNNTree_NodeClick);
            this.Tree.PopulateOnDemand += new DnnTree.DNNTreeEventHandler(this.DNNTree_PopulateOnDemand);
        }

        public override string ControlID
        {
            get
            {
                return this.m_strControlID;
            }
            set
            {
                this.m_strControlID = value;
            }
        }

        public override string CSSBreadCrumbRoot
        {
            get
            {
                return this.m_strCSSBreadCrumbRoot;
            }
            set
            {
                this.m_strCSSBreadCrumbRoot = value;
            }
        }

        public override string CSSBreadCrumbSub
        {
            get
            {
                return this.m_strCSSBreadCrumbSub;
            }
            set
            {
                this.m_strCSSBreadCrumbSub = value;
            }
        }

        public override string CSSControl
        {
            get
            {
                return this.Tree.CssClass;
            }
            set
            {
                this.Tree.CssClass = value;
            }
        }

        public override string CSSIcon
        {
            get
            {
                return this.Tree.DefaultIconCssClass;
            }
            set
            {
                this.Tree.DefaultIconCssClass = value;
            }
        }

        public override string CSSNode
        {
            get
            {
                return this.Tree.DefaultNodeCssClass;
            }
            set
            {
                this.Tree.DefaultNodeCssClass = value;
            }
        }

        public override string CSSNodeHover
        {
            get
            {
                return this.Tree.DefaultNodeCssClassOver;
            }
            set
            {
                this.Tree.DefaultNodeCssClassOver = value;
            }
        }

        public override string CSSNodeHoverRoot
        {
            get
            {
                return this.m_strCSSNodeHoverRoot;
            }
            set
            {
                this.m_strCSSNodeHoverRoot = value;
            }
        }

        public override string CSSNodeHoverSub
        {
            get
            {
                return this.m_strCSSNodeHoverSub;
            }
            set
            {
                this.m_strCSSNodeHoverSub = value;
            }
        }

        public override string CSSNodeRoot
        {
            get
            {
                return this.m_strCSSNodeRoot;
            }
            set
            {
                this.m_strCSSNodeRoot = value;
            }
        }

        public override string CSSNodeSelectedRoot
        {
            get
            {
                return this.m_strNodeSelectedRoot;
            }
            set
            {
                this.m_strNodeSelectedRoot = value;
            }
        }

        public override string CSSNodeSelectedSub
        {
            get
            {
                return this.m_strNodeSelectedSub;
            }
            set
            {
                this.m_strNodeSelectedSub = value;
            }
        }

        public override string ForceDownLevel
        {
            get
            {
                return this.Tree.ForceDownLevel.ToString();
            }
            set
            {
                this.Tree.ForceDownLevel = Convert.ToBoolean(value);
            }
        }

        public override string IndicateChildImageExpandedRoot
        {
            get
            {
                return this.Tree.ExpandedNodeImage;
            }
            set
            {
                this.Tree.ExpandedNodeImage = value;
            }
        }

        public override string IndicateChildImageExpandedSub
        {
            get
            {
                return this.Tree.ExpandedNodeImage;
            }
            set
            {
                this.Tree.ExpandedNodeImage = value;
            }
        }

        public override string IndicateChildImageRoot
        {
            get
            {
                return this.Tree.CollapsedNodeImage;
            }
            set
            {
                this.Tree.CollapsedNodeImage = value;
            }
        }

        public override string IndicateChildImageSub
        {
            get
            {
                return this.Tree.CollapsedNodeImage;
            }
            set
            {
                this.Tree.CollapsedNodeImage = value;
            }
        }

        public override bool IndicateChildren
        {
            get
            {
                return this.m_blnIndicateChildren;
            }
            set
            {
                this.m_blnIndicateChildren = value;
            }
        }

        public override Control NavigationControl
        {
            get
            {
                return this.Tree;
            }
        }

        public override string PathImage
        {
            get
            {
                return this.m_strPathImage;
            }
            set
            {
                this.m_strPathImage = value;
            }
        }

        public override string PathSystemImage
        {
            get
            {
                return this.Tree.SystemImagesPath;
            }
            set
            {
                this.Tree.SystemImagesPath = value;
            }
        }

        public override string PathSystemScript
        {
            get
            {
                return this.Tree.TreeScriptPath;
            }
            set
            {
            }
        }

        public override bool PopulateNodesFromClient
        {
            get
            {
                return this.Tree.PopulateNodesFromClient;
            }
            set
            {
                this.Tree.PopulateNodesFromClient = value;
            }
        }

        public override bool SupportsPopulateOnDemand
        {
            get
            {
                return true;
            }
        }

        public DnnTree Tree
        {
            get
            {
                return this.m_objTree;
            }
        }

        public override string WorkImage
        {
            get
            {
                return this.Tree.WorkImage;
            }
            set
            {
                this.Tree.WorkImage = value;
            }
        }
    }
}

